package com.yc.fav.servlet;

import com.ly.fav.util.MBHelper;
import com.yc.fav.dao.TagMapper;
import com.yc.fav.entity.Tag;
import com.yc.fav.entity.User;
import com.yc.fav.util.Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/10/31
 * Email haijunzhou@hnit.edu.cn
 */
@WebServlet("/myTags")
public class MyTagsServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User myinfo = (User) req.getSession().getAttribute("myinfo");
        if(myinfo!=null){
            List<Tag> tags = MBHelper.execute(session -> {
                TagMapper mapper = session.getMapper(TagMapper.class);
                return mapper.selectByUid(myinfo.getId());
            });
            Utils.output(resp, tags);
        }
    }
}
